{% extends 'base.html' %}
{% load mytags %}

{% block css %}
    <link rel="stylesheet" href="/static/css/dataTables.bootstrap.min.css">
    <link href="/static/xadmin/css/xadmin.plugins.css" type="text/css" media="screen" rel="stylesheet" />
    <style>
        .scroll {
            position: relative;
        }
    </style>
{% endblock %}

{% block content %}
    <section class="content-header">
        <h1>
            操作权限列表
        </h1>
        <ol class="breadcrumb">
            <li><a href="#"><i class="fa fa-server"></i> 权限管理</a>
            <li><a href="#"> 操作权限</a></li>
            <li class="active"><a href="#">操作权限列表</a></li>
        </ol>
    </section>
    <!-- Main content -->
    <section class="content">
        <!-- Small boxes (Stat box) -->
        <div class="row">
            <div class="col-xs-12">
                <div class="box box-warning">
                    <div class="box-header">
                        <div class="btn-group col-md-1">
                            <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown"
                                    aria-haspopup="true" aria-expanded="false" style="color: #2b542c;">
                                  {{ paginate_by }}     <span class="caret"></span>
                            </button>
                            <ul class="dropdown-menu">
                                <li><a href="#">5</a></li>
                                <li><a href="#">10</a></li>
                                <li><a href="#">20</a></li>
                                <li><a href="#">50</a></li>
                                <li><a href="#">100</a></li>
                            </ul>

                        </div>
                        <div class="col-md-3">
                        <form action="{% url 'accounts:usergroup_search' %}" method="get">
                            <div class="input-group search-group">
                                <input id="searchbar" class="form-control" type="text" name="q" placeholder="搜索 用户组">
                                <span class="input-group-btn">
                                    <button class="btn btn-primary" type="submit">
                                        <i class="fa fa-search"></i>
                                    </button>
                                </span>
                            </div>
                        </form>
                        </div>
                        <a href="{% url 'permission:action_permission_list' %}">
                            <button class="btn btn-success pull-right">
                                <span class="glyphicon glyphicon-plus"></span>添加资产操作权限
                            </button>
                        </a>
                    </div>
                    <!-- /.box-header -->
                    <div class="box-body">
                        <table id="example1" class="table table-bordered table-striped">
                            <thead>
                            <tr>
                                <th scope="col" class="action-checkbox-column">
                                    <input type="checkbox" id="action-toggle">
                                </th>
                                <th>权限名</th>
                                <th>权限</th>
                                <th>对象名称</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            {% for permission in permission_list %}
                                <tr>
                                    <td class="action-checkbox">
                                        <input class="action-select" type="checkbox" name="select_action"
                                               value="{{ usergroup.pk }}">
                                    </td>
                                    <td>{{ permission.name }}</td>
                                    <td>{{ permission.codename }}</td>
                                    <td>{{ permission.content_type }}</td>
                                    <td>
                                        <a href="{% url 'accounts:user_detail' user.pk %}">
                                            <button class="btn btn-primary btn-xs">详情</button>
                                        </a>
                                        <a href="{% url 'accounts:user_edit' user.pk %}">
                                            <button class="btn btn-warning btn-xs">编辑</button>
                                        </a>
                                        <a href="{% url 'permission:user_permission_list' user.pk %}">
                                            <button class="btn btn-success btn-xs">绑定用户</button>
                                        </a>
                                        <button class="btn btn-danger btn-xs" data-toggle="modal"
                                                data-target="#{{ user.pk }}">
                                            删除
                                        </button>
                                        <div class="modal fade" id="{{ user.pk }}" tabindex="-1" role="dialog"
                                             aria-labelledby="myModalLabel">
                                            <div class="modal-dialog" role="document">
                                                <div class="modal-content">
                                                    <div class="modal-header">
                                                        <button type="button" class="close" data-dismiss="modal"
                                                                aria-label="Close">
                                                            <span aria-hidden="true">&times;</span></button>
                                                        <h4 class="modal-title" id="myModalLabel"
                                                            style="color: #953b39;">用户删除</h4>
                                                    </div>
                                                    <div class="modal-body">
                                                        <p>
                                                            确定要删除用户
                                                            <a href="">{{ user.username }}</a>？
                                                        </p>
                                                    </div>
                                                    <div class="modal-footer">
                                                        <form action="{% url 'accounts:user_del' user.pk %}" method="POST">
                                                            {% csrf_token %}
                                                            <button type="submit" class="btn btn-danger">
                                                                删除
                                                            </button>
                                                            <button type="button" class="btn btn-default"
                                                                    data-dismiss="modal">取消
                                                            </button>
                                                        </form>
                                                    </div>
                                                </div>
                                                <!-- /.modal-content -->
                                            </div>
                                            <!-- /.modal-dialog -->
                                        </div>
                                    </td>
                                </tr>
                            {% endfor %}
                        </table>
                    </div>
                    <!-- /.box-body -->
                    <div class="well well-sm">
                        <input type="hidden" id="action" name="action" value=""/>
                        <input type="hidden" id="select-across" name="select_across" value=""/>
                        <div class="btn-group clearfix dropup">
                            <a class="dropdown-toggle btn btn-primary" data-toggle="dropdown" href="#">
                                <i class="fa fa-wrench"></i>
                                <span class="action-counter">{{ permission_list.count }} 个中 0 个被选</span>
                                <span class="all" style="display: none;">选中了 11 个</span>
                                <span class="caret"></span></a>
                            <ul class="dropdown-menu" role="menu" aria-labelledby="dLabel">

                                <li><a onclick="$.do_action('delete_selected');"><i class="fa fa-times"></i> 删除所选的
                                    用户组</a></li>

                            </ul>
                        </div>
                        <ul class="btn-group pagination pull-right" style="margin-top: 1px;">
                            {% if page_obj.has_previous %}
                                <li class="previous">
                                    <a href="?page={{ page_obj.previous_page_number }}">上一页 <span class="sr-only">(current)</span></a>
                                </li>
                            {% else %}
                                <li class="previous disabled">
                                    <a>上一页 <span class="sr-only">(current)</span></a>
                                </li>
                            {% endif %}

                            {% pagination page_obj paginator 10 4 as page_list %}

                            {{ page_list|safe }}

                            {% if page_obj.has_next %}
                                <li class="next">
                                    <a href="?page={{ page_obj.next_page_number }}">下一页 <span
                                            class="sr-only">(current)</span></a>
                                </li>
                            {% else %}
                                <li class="next disabled">
                                    <a>下一页 <span class="sr-only">(current)</span></a>
                                </li>
                            {% endif %}
                        </ul>
                    </div>

                </div>
            </div>
        </div>
    </section>

{% endblock %}

{% block js %}
    <script src="/static/js/jquery.dataTables.min.js"></script>
    <script src="/static/js/dataTables.bootstrap.min.js"></script>
    <script>
        $('.scroll').scrollspy({target: '#navbar-example'});
        $('[data-spy="scroll"]').each(function () {
            var $spy = $(this).scrollspy('refresh')
        });
        $(document).ready(function () {
            $('.pagination li a').each(function () {
                if ($(this).html() == {{ page_obj.number }}) {
                    $(this).parent().addClass('active')
                }
            });
            $('#g-4').addClass('active');
            $('#g-4-2').addClass('active');
        });
    </script>
{% endblock %}